home *** CD-ROM | disk | FTP | other *** search
- /*
- * Test writing an external function for ProIcon
- *
- * This code resource will appear under the resource type 'TEST', ID 1005,
- * name "External Test". Invoke with:
- *
- * callout("TEST", "External Test", int)
- *
- * It accepts an integer argument and returns an external block containing
- * that many 32-bit words of junk data.
- */
-
-
- #include "ProIcon.h"
-
- /*
- * Code resource called as:
- * callout("type", "resource name", ...)
- * where:
- * "type" is a Macintosh 4-character resource type code
- * "resource name" is a string used to specify resource by name.
- * ... are additional arguments whose dptrs are pushed on the stack.
- *
- * dargv[0] - Arg0 - descriptor to place result
- * dargv[1] - Arg1 - first user argument
- * dargv[argc] - Argn - last user argument
- * ip - pointer to integer used to signal error. *ip is initialized
- * to -1, signifying no error.
- *
- * Possible returns:
- * Success - Leave *ip unaltered, return descriptor pointer.
- * Failure - Leave *ip unaltered, return NULL.
- * Error - Set *ip to error code >= 0. Return descriptor pointer or NULL
- * to have value displayed or not displayed in error message.
- */
-
- pascal dptr main(dargv, argc, ip, callback)
- dptr dargv;
- short int argc;
- short int *ip;
- pointer (*callback)();
- {
- register struct b_external *bp;
- word i, j;
-
- if (argc != 1) /* fail if wrong number of arguments */
- Fail;
-
- if (Type(Arg1) != T_Integer)
- RunErr(Err101, &Arg1); /* integer expected for first user arg */
-
- if ((i = IntVal(Arg1)) <= 0)
- RunErr(Err205, &Arg1); /* argument out of range */
-
- j = i * sizeof(word) + (sizeof(struct b_external) - WordSize);
-
- if (blkreq(j) == Error) /* notify ProIcon of memory needs */
- RunErr(0, NULL);
-
- ArgType(0) = D_External; /* set external result code */
- bp = alcextrnl(i);
- BlkLoc(Arg0) = (union block *)bp; /* point to block containing external data */
- for (j = 0; j < i; j++) /* fill block with junk data */
- bp->exdata[j] = j;
-
- Return;
- }
-